package com.example.book_recommend.controller;

import com.example.book_recommend.entity.BookInfo;
import com.example.book_recommend.pojo.VueResultInfo;
import com.example.book_recommend.service.BookService;
import com.example.book_recommend.utils.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@EnableAutoConfiguration
@CrossOrigin
@RequestMapping("api/book")
public class BookController {
    @Autowired
    BookService bookService;

    /**
     * 这是一个示例！！！！！需要被完善！！！
     * @param bookInfo
     * @param bindingResult
     * @return
     */
    @RequestMapping("search")
    public VueResultInfo search(@RequestBody @Valid BookInfo bookInfo, BindingResult bindingResult){

        System.out.println(bookInfo.getBookId());
        return ResultFactory.buildSuccessResult(bookService.getBookInfo(bookInfo.getBookId().intValue()));
    }
}
